#include "sophomore_widget.h"
#include <QCheckBox>
#include <QPushButton>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QtDebug>
#include <QLabel>
#include <QSpinBox>
#include <QLineEdit>
#include <QFile>
#include <QTextStream>
SophomoreWidget::SophomoreWidget(QWidget *parent)
    : QWidget(parent)
    , m (new Math(this))
    , m_checkboxFun1(new QCheckBox())
    , m_checkboxFun2(new QCheckBox())
    , m_checkboxFun3(new QCheckBox())
    , m_checkboxFun4(new QCheckBox())
    , m_layoutNum(new QHBoxLayout)
    , m_layoutMain(new QVBoxLayout)
    , m_btn(new QPushButton("生成题目",this))
    , m_labNum(new QLabel("题目数量："))
    , m_SpinBoxNum(new QSpinBox)
{
    initUI();
    initConnect();
}

void SophomoreWidget::slotClickBtn()
{
    functionPointers.clear();
    if(m_checkboxFun1->isChecked()){
          functionPointers.push_back(&Math::fun1);
    }
    if(m_checkboxFun2->isChecked()){
          functionPointers.push_back(&Math::fun2);
    }

    if(m_checkboxFun3->isChecked()){
          functionPointers.push_back(&Math::fun3);
    }

    if(m_checkboxFun4->isChecked()){
          functionPointers.push_back(&Math::fun4);
    }

    for (int i = 0 ; i< 700; i++) {
        int r =   m->generateRandomNumber(0,functionPointers.size()-1);
        QString result = (m->*(functionPointers[r]))();
        qWarning()<< result;
    }
}

void SophomoreWidget::initUI()
{
    m_checkboxFun1->setText("题型:a*b+c");
    m_checkboxFun1->setChecked(true);
    m_checkboxFun2->setText("题型:a*b-c");
    m_checkboxFun2->setChecked(true);
    m_checkboxFun3->setText("题型:a*b+c");
    m_checkboxFun3->setChecked(true);
    m_checkboxFun4->setText("题型:a*b-c");
    m_checkboxFun4->setChecked(true);
    m_SpinBoxNum->setMaximum(1000);
    m_SpinBoxNum->setValue(100);
    m_layoutNum->addWidget(m_labNum);
    m_layoutNum->addWidget(m_SpinBoxNum);
    m_layoutMain->addLayout(m_layoutNum);
    m_layoutMain->addWidget(m_btn);
    m_layoutMain->addWidget(m_checkboxFun1);
    m_layoutMain->addWidget(m_checkboxFun2);
    m_layoutMain->addWidget(m_checkboxFun3);
    m_layoutMain->addWidget(m_checkboxFun4);
    setLayout(m_layoutMain);
}

void SophomoreWidget::initConnect()
{
    connect(m_btn,&QPushButton::clicked,this,&SophomoreWidget::slotClickBtn);
}

void SophomoreWidget::saveFile(QString fileName)
{

}
